package es.cea.agendatelefonica;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

/**
 * Servlet Filter implementation class FiltroBorrado
 */
public class FiltroAgenda implements Filter {

    public FiltroAgenda() {
        // TODO Auto-generated constructor stub
    }

	public void destroy() {
		// TODO Auto-generated method stub
	}

	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		// TODO Auto-generated method stub
		// place your code here
	
		HttpServletRequest req=(HttpServletRequest) request;
		
		
		if (req.getSession().getServletContext().getAttribute("emf") != null){
			// Filtra el request impidiendo que siga la ejecucion normal.
			System.out.println("Pagina principal agenda. Entity Factory almacenanda correcmtante");
//			request.getRequestDispatcher("/agenda").forward(request, response);
			chain.doFilter(request, response);
		} else {
			System.out.println("La factoria de entidades no esta bien creada");
		}
//		
		
	}

	public void init(FilterConfig fConfig) throws ServletException {
		// TODO Auto-generated method stub
	}

}
